<?php
/*
 * (C) Copyright 2013 Torsten Gorath (http://www.blauesdach.de/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     Torsten Gorath
 */
$basedir = dirname(__FILE__);
require_once $basedir.'/inc/menu.php';
//include_once $basedir . "/inc/authorized.inc.php";
$menuid = $_REQUEST['page'];
$menu = new Menu($menuid);
$action = "";
if(isset($_REQUEST['action'])) {
    $action = $_REQUEST['action'];
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<!--    <meta http-equiv="content-type" content="text/html; charset=utf-8">-->
    <link type="text/css" href="css/jquery-ui.css" rel="stylesheet" />
    <link type="text/css" href="css/main.css" rel="stylesheet" />
    <link type="text/css" href="css/jquery.memu.css" rel="stylesheet" />
    <script type="text/javascript" src="js/functions.js"></script>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery-ui.js"></script>
    <script type="text/javascript" src="js/jquery.memu.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/jquery.ui.autocomplete.html.js"></script>
    <title>Verein</title>
    <script>
    	$(function() {
    		$('#menu').memu({
    			icon: {
    				insert: true,
    				margin: {
    					top: 4,
    					right: 10
    				}
    			},
    			width: 150,
    			rootWidth: 100,
    			height: 25
    		});
            $('input[name$="_am"]').datepicker({
                'dateFormat': 'yy-mm-dd'
            });
            $('input[name$="_ab"]').datepicker({
                'dateFormat': 'yy-mm-dd'
            });
            $('input[name$="_auto_address"]').autocomplete({
                source : function(request, response) {
                    var data = {
                        'value' : request.term,
                        'page' : 'stammdaten_adress',
                        'action' : 'search'
                    };
                    $.ajax({
                        'url' : "json.php",
                        'data' : data,
                        'type' : 'post',
                        'dataType' : 'json',
                        'success' : function(data) {
                            response(data.items);
                        }
                    })
                },
                minLength : 2,
                select : function(event, ui) {
                    var item = ui.item;
                    var name = $(this).attr('name').replace('_auto_address', '_id');
                    var $id = $('input[name="' + name + '"]');
                    if($id != null) {
                        $id.attr('value', ui.item.id);
                    }
                },
                response : function(event, ui) {
                    for (var i = 0; i < ui.content.length; i++) {
                        ui.content[i].label = ui.content[i].vorname + " " + ui.content[i].nachname;
                        ui.content[i].value = ui.content[i].label;
                    }
                }
            });
    	});
    </script>
  </head>
  <body>
      <div>
          <div id='menubar'><?php $menu->show();?></div>
          <div class='content'>
<?php if(file_exists($basedir."/pages/".$menuid.".php")) {
    include $basedir."/pages/".$menuid.".php";
} else {
    include $basedir."/pages/overview.php";
}?>
          </div>
      </div>
  </body>
</html>
